package model;

import java.sql.Timestamp;


import dao.ReservationDAO;

public class Reservation {
       
        private int id;
        private Timestamp created;
        private Timestamp modified;
        private Timestamp reservation_date;
        private String user_name;
        private int active;

        private ReservationDAO reservationDAO;
        
        public Reservation(){
        	reservationDAO = new ReservationDAO();        
        }
               
        public int getId() {return id;}        
        public Timestamp getCreated() {return created;}
        public Timestamp getModified() {return modified;}
        public Timestamp getReservation_date() {return reservation_date;}
        public String getUser_name() {return user_name;}
        public int getActive() {return active; }
        
        public void setId(int id) {this.id = id;}        
        public void setCreated(Timestamp created) {this.created = created;}
        public void setModified(Timestamp modified) {this.modified = modified;}
        public void setReservation_date(Timestamp reservation_date) {this.reservation_date = reservation_date;}
        public void setUser_name(String user_name) {this.user_name = user_name;}
        public void setActive(int a) {active = a;}
        
        public boolean reserve(Timestamp resdate, String username) {
        			
			java.util.Date today = new java.util.Date();
		    java.sql.Timestamp now = new java.sql.Timestamp(today.getTime());
			
			Reservation r = new Reservation();
			r.setCreated(now);
			r.setModified(now);
			r.setReservation_date(resdate);
			r.setUser_name(username);
			r.setActive(1);
			
			reservationDAO.create(r);
			
			return true;       	
        }       
        
        public boolean modify(int id, Timestamp newdate) {
        	Reservation r = reservationDAO.select(id);
        	
        	if ( r != null ) {
        		r.setReservation_date(newdate);
        		reservationDAO.update(r);
        		
        		return true;
        	}
        	
        	return false;
        }
        
        public boolean cancel(int id) {
        	Reservation r = reservationDAO.select(id);
        	
        	if ( r != null ) {
        		r.setActive(0);
        		reservationDAO.update(r);
        		
        		return true;
        	}
        	
        	return false;	
        }
}
